package org.films.domain;

import javax.persistence.Entity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;
import org.springframework.roo.addon.entity.RooEntity;
import javax.validation.constraints.NotNull;
import java.util.Calendar;

import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;

import org.springframework.format.annotation.DateTimeFormat;
import java.util.Set;
import org.films.domain.Film;
import java.util.HashSet;
import javax.persistence.ManyToMany;
import javax.persistence.CascadeType;

@Entity
@RooJavaBean
@RooToString
@RooEntity
public class Actor {

    @NotNull
    private String name;

    @NotNull
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(style = "S-")
    private Calendar birthDay;

    @ManyToMany(cascade = {CascadeType.REFRESH, CascadeType.MERGE})    
	@JoinTable(name = "FILM_ACTOR", joinColumns = { @JoinColumn(name = "ACTOR_ID") }, inverseJoinColumns = @JoinColumn(name = "FILM_ID"), uniqueConstraints = { @UniqueConstraint(columnNames = {
			"ACTOR_ID", "FILM_ID" }) })
    private Set<Film> films = new HashSet<Film>();
}
